home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 12 / Amiga Format AFCD12 (Apr 1997, Issue 96).iso / -readerstuff- / manolis_pappas / mathfx / examples / demo.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-01-29  |  2.6 KB  |  106 lines

  1. /* Demonstration program for MathFX library. */
  2. /* Copyright (©) 1995, The Xperts Group Inc. All Rights Reserved. */
  3. /* Author: Manolis S Pappas. */
  4.  
  5. /* Plots three simple functions, each function occupies a separate page */
  6.  
  7. #include <stdio.h>
  8. #include <math.h>
  9.  
  10. static float xs[6] = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0};
  11. static float ys[6] = {1.0, 4.0, 9.0, 16.0, 25.0, 36.0};
  12. static int space0 = 0;
  13. static int mark0 = 0;
  14. static int space1 = 1500;
  15. static int mark1 =1500;
  16.  
  17. main()
  18. {
  19.       int i;
  20.       float x[101], y[101];
  21.  
  22. /* Ask user to specify the output device */
  23.  
  24.       fxstar(1,1);
  25.  
  26. /* Set up the viewport and window using FXENV. The range in X is */
  27. /* 0.0 to 6.0, and the range in Y is 0.0 to 30.0. The axes are */
  28. /* scaled separately (just = 0), and we just draw a labelled */
  29. /* box (axis = 0). */
  30.  
  31.       fxenv(0.0,6.0,0.0,30.0,0,0);
  32.       fxlab("(x)","(y)","\\frExample Plot - y=x\\u2");
  33.  
  34. /* Plot the data points */
  35.  
  36.       fxpoin(6,xs,ys,9);
  37.  
  38.       for (i=0; i<60; i++) {
  39.         x[i]=0.1*(i+1);
  40.         y[i]= pow(x[i],2.);
  41.       }
  42.  
  43. /* Draw the line through the data */
  44.  
  45.       fxline(60,x,y);
  46.  
  47. /*======================================================================*/
  48.  
  49. /* Set up the viewport and window using FXENV. The range in X is */
  50. /*  -2.0 to 10.0, and the range in Y is -0.4 to 2.0. The axes are */
  51. /*  scaled separately (just = 0), and we draw a box with axes */
  52. /*  (axis = 1). */
  53.  
  54.       fxenv(-2.0,10.0,-0.4,1.2,0,1);
  55.       fxlab("(x)","sin(x)/x","\\frSinc Function Plot");
  56.  
  57. /* Fill up the arrays */
  58.  
  59.       for (i=0; i<100; i++) {
  60.         x[i] = (i-19.0)/6.0;
  61.         y[i] = 1.0;
  62.         if (x[i] != 0.0) y[i] = sin(x[i])/x[i];
  63.       }
  64.  
  65. /* Draw the line */
  66.  
  67.       fxline(100,x,y);
  68.  
  69. /*======================================================================*/
  70.  
  71. /* For the final graph we wish to override the default tick intervals, */
  72. /* and so do not use FXENV */
  73.  
  74.       fxadv(0);
  75.  
  76. /* Use standard viewport, and define X range from 0 to 360 degrees, */
  77. /* Y range from -1.2 to 1.2. */
  78.  
  79.       fxvsta();
  80.       fxwind(0.0,360.0,-1.2,1.2);
  81.  
  82. /* Draw a box with ticks spaced 30 degrees apart in X, and 0.2 in Y. */
  83.  
  84.       fxbox("bcnst",30.0,3,"bcnstv",0.2,2);
  85.  
  86. /* Superimpose a dashed line grid, with 1.5 mm marks and spaces. */
  87. /* fxstyl expects a pointer!! */
  88.  
  89.       fxstyl(1,&mark1,&space1);
  90.       fxbox("g",30.0,3,"g",0.2,2);
  91.       fxstyl(0,&mark0,&space0);
  92.  
  93.       fxlab("Angle (degrees)","sine","\\frSine function Plot");
  94.  
  95.       for (i=0; i<101; i++ ) {
  96.         x[i] = 3.6 * i;
  97.         y[i] = sin(x[i]*3.141592654/180.0);
  98.       }
  99.  
  100.       fxline(101,x,y);
  101.  
  102. /* Don't forget to call FXEND to finish off! */
  103.  
  104.       fxend();
  105. }
  106.